package org.yang.common.core.annotation.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.yang.common.core.annotation.Chinese;
import org.yang.common.core.constant.RegularConstant;

import java.util.regex.Pattern;

/**
 * @author: lslands
 * @version: 1.0
 * @create: 2024/5/19
 * @description:
 */
public class ChineseValidation implements ConstraintValidator<Chinese,String> {

    private static final Pattern REGEX=Pattern.compile(RegularConstant.NO_CHINESE_SYMBOL);

    /**
     * 初始化，获取是否强校验
     * @param constraintAnnotation
     */
    @Override
    public void initialize(Chinese constraintAnnotation) {
        boolean isRequired = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (null==value) {
            return true;
        } else {
            return !REGEX.matcher(value).find();
        }
    }
}
